﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 新增考勤记录表 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SysAttendanceRecord",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    PersonId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    AttendanceShiftId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ShiftType = table.Column<int>(type: "int", nullable: false),
                    ScheduleType = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    Remark = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    ShiftDate = table.Column<DateOnly>(type: "date", nullable: false),
                    StartTime = table.Column<TimeOnly>(type: "time", nullable: true),
                    EndTime = table.Column<TimeOnly>(type: "time", nullable: true),
                    SubstitutePersonId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    SwapShiftId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    AttendanceResult = table.Column<int>(type: "int", nullable: false),
                    LateMinutes = table.Column<int>(type: "int", nullable: true),
                    EarlyLeaveMinutes = table.Column<int>(type: "int", nullable: true),
                    WorkMinutes = table.Column<int>(type: "int", nullable: true),
                    MissingPunchCount = table.Column<int>(type: "int", nullable: true),
                    IsAbnormal = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysAttendanceRecord", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysAttendanceRecord_SysAttendanceShift_AttendanceShiftId",
                        column: x => x.AttendanceShiftId,
                        principalTable: "SysAttendanceShift",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SysAttendanceRecord_SysPerson_PersonId",
                        column: x => x.PersonId,
                        principalTable: "SysPerson",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SysAttendanceRecord_SysPerson_SubstitutePersonId",
                        column: x => x.SubstitutePersonId,
                        principalTable: "SysPerson",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysAttendanceRecord_AttendanceShiftId",
                table: "SysAttendanceRecord",
                column: "AttendanceShiftId");

            migrationBuilder.CreateIndex(
                name: "IX_SysAttendanceRecord_PersonId",
                table: "SysAttendanceRecord",
                column: "PersonId");

            migrationBuilder.CreateIndex(
                name: "IX_SysAttendanceRecord_SubstitutePersonId",
                table: "SysAttendanceRecord",
                column: "SubstitutePersonId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SysAttendanceRecord");
        }
    }
}
